<?php
/* @var $this SearchController */

$this->breadcrumbs=array(
	'Tìm kiếm',
);
//CVarDumper::dump($models,10,true);die();
?>
<div class="container white-bg" id="<?php echo $this->id.'-page'?>">
   <div class="slide-container relative">
   <!-- Slideshow 1 -->
    <ul class="rslides" id="slide-show">
      <li><img src="images/7.jpg" alt=""></li>
      <li><img src="images/8.jpg" alt=""></li>
      <li><img src="images/9.jpg" alt=""></li>
    </ul>
   </div>
   
   <div class="slogan relative text-center">
      <p>Chào mừng bạn đến với website Bất Động Sản</p>
      <span class="absolute">Nơi mang lại cho bạn những thông tin kết nối hữu ích</span>
   </div>
   <div class="main-content">
      <div class="left">
         <?php if(count($models) > 0){?>
            <div class="list-news list-post">
               <div class="caption-label relative left"> 
                  <em class="arrow half-arrow-down sprite absolute"></em>
                  <span class="font-opensans">Nhà đất bán</span>
               </div>
               <div class="clear"></div>
               <ul>
                  <?php 
                  $i = 0;
                  foreach($models as $model){
                     $link = $model->linkDetail($model->post_id,$model->post_title);
                     $i++;
                     ?>
                  <li class="post-item">
                     <a href="<?php echo $link?>">
                        <p class="title <?php if($model->post_vip) echo 'highlight'?> bold font-opensans"><?php echo $model->post_title?></p>
                        <div class="img-wrap left">
                           <img src="<?php echo Yii::app()->params['path_image_post'].$model->post_avatar;?>" />
                        </div>
                     </a>
                     <div class="text">
                        <div class="summary">
                           <?php echo Str::cutString(Str::removeHTML($model->post_content),300)?>
                        </div>
                        <ul class="">
                           <li>
                              <span>Giá:</span>
                              <span class="highlight bold"><?php echo CVietnameseTools::readCurrentcy($model->post_price);?></span>
                           </li>
                           <li>
                              <span>Diện tích:</span>
                              <span class="highlight bold"><?php echo $model->post_area?> m²</span>
                           </li>
                           <li>
                              <?php 
                                 $district = is_null($model->getRelated('district')) ? 'Chưa rõ' : $model->getRelated('district')->dis_name;
                                 $province = is_null($model->getRelated('province')) ? 'Chưa rõ' : $model->getRelated('province')->prv_name;
                              ?>
                              <span>Quận/Huyện:</span>
                              <span class="highlight bold"><?php echo $district . ' ,' . $province?></span>
                           </li>  
                           <li class="right">
                              <span class="date"><?php echo date('d/m/Y',$model->post_date_update)?></span>
                           </li>                      
                        </ul>
                     </div>
                  </li>
                  <?php }?>
               </ul>
               <div class="right">
               <?php 
                  $pagination->render();
               ?>
               </div>
            </div>
         <?php }else{
            echo Str::notificationBox('warning','Không có nội dung phù hợp với từ khóa của bạn','Cảnh báo');
         }
         ?>
         
      </div><!-- End left-content-->
      <div class="right">
         <div class="search-container">
            <div class="caption uppercase text-center relative font-opensans bold"><i class="sprite absolute icon-house"></i>Công cụ tìm kiếm</div>
            <?php 
               //Danh sach tinh thanh
               $list_province = array(0 => '-- Tỉnh/Thành Phố --'); // Danh sách các Tỉnh/Tp
               $province = new Province();
               $object = $province->findAll(array(
                  'order' => 'prv_order DESC, prv_name ASC',
               ));
               
               //Danh sach danh muc
               $list_category = array();
               $category = new Category();
               $all_cate = $category->getAll();
               $tree_cate = $category->getTree($all_cate);
               $tree_cate[0] = '-- Danh mục nhà đất --';
               if(count($object) > 0){
                  foreach($object as $item){
                     $list_province[$item->attributes['prv_id']] = $item->attributes['prv_name'];
                  }
               }
               
               //Danh sach quan huyen
               $list_district = array(0 => '-- Quận/Huyện --');
               $model = new Post();
               if($model->post_prv_id > 0){
                  $object = District::model()->getAllByPrvID($model->post_prv_id);
                  foreach($object as $item){
                     $list_district[$item['dis_id']] = $item['dis_name'];
                  }
               }
               
               //Danh sach cac du an
               $list_project = array(0 => '-- Dự án --');
               if($model->post_prv_id > 0){
                  $object = Project::model()->findAllByAttributes(array('prj_dis_id' => $model->post_dis_id));
                  foreach($object as $item){
                     $list_project[$item['prj_id']] = $item['prj_name'];
                  }
               }
               
               //Lua chon dien tich
               $list_area = array('0' => '-- Chọn mức giá --',
                                  '0,30' => 'Dưới 30 m2',
                                  '30,50' => '30 - 50 m2',
                                  '50,100' => '50 - 100 m2',
                                  '100,200' => '100 -200 m2',
                                  '200,500' => '200 - 500 m2',
                                  '500,1000' => '500 - 1000 m2',
                                  '1000' => 'Trên 1000 m2');
            ?>
            <?php $model = new Post();?>
            <div class="form-search" id="<?php echo Yii::app()->controller->id . '-' . Yii::app()->controller->action->id?>">
               <?php $form=$this->beginWidget('CActiveForm', array(
               	'id'=>Yii::app()->controller->id . '_' . Yii::app()->controller->action->id,
               	'action' => '/post',
                  'method' => 'GET',
                  'enableAjaxValidation'=>false,
                  'enableClientValidation'=>false
               )); ?>
               
               <?php echo $form->errorSummary($model,'Kiểm tra lại các giá trị bạn vừa nhập vào'); ?>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_cat_id',$tree_cate);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_prv_id',$list_province);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_dis_id',$list_district);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_prj_id',$list_project);?>
               </div>
               <div class="row">
                  <?php echo $form->dropDownList($model, 'post_area',$list_area);?>
               </div>
               <div class="row text-right relative">
                  <?php echo CHtml::submitButton('Tìm kiếm',array('id' => 'submit-search'))?>
               </div>   
               <?php $this->endWidget(); ?>
            </div> 
         </div> <!-- End search-container -->
         <div class="video-embed">
            <iframe width="310" height="205" src="//www.youtube.com/embed/Q87KqUk36w8" frameborder="0" allowfullscreen></iframe>
         </div>
         <div class="focus-last-week">
            <?php
               $criteria = new CDbCriteria();
               $criteria->offset = 0;
               $criteria->limit = 10;
               $criteria->order = 'news_view DESC';
               $list_news = News::model()->findAll($criteria);
            ?>
            <div class="caption uppercase text-center relative font-opensans bold"><i class="sprite absolute icon-focus"></i>Tiêu điểm tuần qua</div>
            <div class="list-news">
               <ul>
                  <?php 
                     $news_model = new News();
                     foreach($list_news as $news){
                     $link = $news_model->linkDetail($news->news_id,$news->news_title)
                     ?>
                     <li class="news-item">
                        <span class="left dots"></span>
                        <a href="<?php echo $link?>"><?php echo $news->news_title?></a>
                     </li>
                  <?php }?>
                  
               </ul>
            </div>
         </div><!-- End focus-last-week -->
         
         <div class="faq">
            <?php
               $question = new Question();
               $criteria = new CDbCriteria();
               $criteria->offset = 0;
               $criteria->limit = 10;
               $criteria->order = 'ques_id DESC';
               $list_ques = Question::model()->findAll($criteria);
            ?>
            <div class="caption uppercase text-center relative font-opensans bold"><i class="sprite absolute icon-question"></i>Hỏi đáp</div>
            <div class="list-question">
               <ul>
                  <?php foreach($list_ques as $ques){
                     $link = $ques->linkDetail($ques->ques_id,$ques->ques_title);
                     ?>
                     <li class="question-item">
                        <span class="left dots"></span>
                        <a href="<?php echo $link?>"><?php echo $ques->ques_title?></a>
                     </li>
                  <?php }?>
               </ul>
            </div>
            <div class="clear"></div>
            <div class="send-question">
               <div class="text-center bold"><span>Gửi câu hỏi của bạn tại đây</span></div>
               
                  <div class="form-faq" id="<?php echo Yii::app()->controller->id . '-' . Yii::app()->controller->action->id?>">
                     <?php $form=$this->beginWidget('CActiveForm', array(
                     	'id'=>'form_send_faq',
                        'action' => '/gui-cau-hoi',
                     	'enableAjaxValidation'=>false,
                        'enableClientValidation'=>false
                     )); ?>                     
                     
                     <div class="row">
                        <?php echo $form->error($question,'ques_use_name');?>
                        <?php echo $form->labelEx($question, 'ques_use_name');?>
                        <?php echo $form->textField($question, 'ques_use_name');?>
                     </div>  
                     <div class="row">
                        <?php echo $form->error($question,'ques_use_email');?>
                        <?php echo $form->labelEx($question, 'ques_use_email');?>   
                        <?php echo $form->textField($question, 'ques_use_email');?>
                     </div>  
                     <div class="row">
                        <?php echo $form->error($question,'ques_title');?>
                        <?php echo $form->labelEx($question, 'ques_title');?>  
                        <?php echo $form->textField($question, 'ques_title');?>
                     </div> 
                     <div class="row">
                        <?php echo $form->error($question,'ques_content');?>
                        <?php echo $form->labelEx($question, 'ques_content');?>  
                        <?php echo $form->textArea($question, 'ques_content');?>
                     </div>                     
                     <div class="row text-center relative">
                        <?php echo CHtml::submitButton('Gửi câu hỏi',array('id' => 'submit-faq'))?>
                     </div>   
                     <?php $this->endWidget(); ?>
                  </div> 
            </div>
         </div><!-- End faq -->
         
         <div class="tags">
            <div>Tags:</div>
            <a href="#">Chung cư Golden West</a>
            <a href="#">Bất động sản</a>
            <a href="#">Vinpearl</a>
            <a href="#">Chung cư Dương Nội</a>
            <a href="#">Chung cư Long Biên</a>
            <a href="#">Chung cư Bắc Hà</a>
            <a href="#">Cho thuê biệt thự</a>
         </div>
      </div><!-- End right-content -->
   </div>
</div>
<script>
   $(document).ready(function(){
      $("#slide-show").responsiveSlides({      
        speed: 800,
        nav: true,
        pager: true,
        auto:true,
      });
      
      $("#Post_order").change(function(){
         $("#form_post_order").submit();
      });
      //Load district
      $("#Post_post_prv_id").change(function(){
         var prv_id = $(this).val();
         data = {'prv_id':prv_id};
         success = function(data){
            $("#Post_post_dis_id").html(data);
         }
         handleAjax('/district/SetDropListByPrvID','GET','',data,success);
      });
      
      //Load project
      $("#Post_post_dis_id").change(function(){
         var dis_id = $(this).val();
         data = {'dis_id':dis_id};
         success = function(data){
            $("#Post_post_prj_id").html(data);
         }
         handleAjax('/project/SetDropListByDisID','GET','',data,success);
      });
   });
</script>